package com.util.description;

import java.util.Arrays;
import java.util.Map;
import java.util.stream.Collectors;

/**
 * @author yutianhong
 * @version 1.0
 * @since 2024/01/02 00:19
 */
public enum PrimitiveTypeDesc implements TypeDesc {
    VOID("V", "void"),
    BOOLEAN("Z", "boolean"),
    BYTE("B", "byte"),
    CHAR("C", "char"),
    SHORT("S", "short"),
    FLOAT("F", "float"),
    INT("I", "int"),
    DOUBLE("D", "double"),
    LONG("J", "long"),
    ;

    private static final Map<String, PrimitiveTypeDesc> typeMap
            = Arrays.stream(values()).collect(Collectors.toMap(PrimitiveTypeDesc::className, e -> e));

    public static PrimitiveTypeDesc getByClassName(String className) {
        return typeMap.get(className);
    }

    private final String className;
    private final String simpleName;

    PrimitiveTypeDesc(String className, String simpleName) {
        this.className = className;
        this.simpleName = simpleName;
    }

    @Override
    public boolean isPrimitive() {
        return true;
    }

    @Override
    public String className() {
        return className;
    }

    public String simpleName() {
        return simpleName;
    }
}
